function formatNumber (n) {
  const str = n.toString()
  return str[1] ? str : `0${str}`
}

export function formatTime (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  const t1 = [year, month, day].map(formatNumber).join('/')
  const t2 = [hour, minute, second].map(formatNumber).join(':')

  return `${t1} ${t2}`
}

/**
 * 获取当前月份有多少天
 */
function getCurrentMonthDayCount () {
  const date = new Date()
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const d = new Date(year, month, 0)
  return d.getDate()
}

function getCurrentMonth () {
  const date = new Date()
  return date.getMonth() + 1
}

function getCurrentDay () {
  const date = new Date()
  return date.getDate()
}

export default {
  formatNumber,
  formatTime,
  getCurrentMonthDayCount,
  getCurrentMonth,
  getCurrentDay
}
